import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        // 登陆用户信息
        adminInfo: null,
        msgModal: {
            error: '',
            success: ''
        },
        // 定位监控 ==> 客户信息
        positionUser: null,
        loadingShow: false,
        // 批量搜索状态
        isBatchSearch: false
    },
    mutations: {
        setAdmin (state, data) {
            state.adminInfo = data
        },
        setPositionUser (state, data) {
            state.positionUser = data
        },
        showAlert (state, data) {
            if (data.error) {
                state.msgModal.error = data.error
                state.msgModal.success = ''
            } else {
                state.msgModal.success = data.success
                state.msgModal.error = ''
            }
            $('#msgModal').modal('toggle')
        },
        showLoading (state, data) {
            state.loadingShow = data === 'show'
        },
        setSearchState (state, data) {
            state.isBatchSearch = data
        }
    }
})

export default store
